package com.startsola;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;

import java.util.Arrays;

public class Roboot {
    public static void send(String str, boolean isTrue){

        try {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=cc14f16343aa5935b7236467ea7717fb43e071766667b997178eb64a1286b383");
            OapiRobotSendRequest request = new OapiRobotSendRequest();


            OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
            at.setAtMobiles(Arrays.asList("13751850024"));
            request.setAt(at);


            request.setMsgtype("markdown");

            OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
            markdown.setTitle("李四");
            if (isTrue) {
                markdown.setText("#### 有号 @13751850024\n" +
                    "```html\n" + str +
                    "\n```");
            } else {
                markdown.setText("```html\n" + str +
                    "\n```");
            }
            request.setMarkdown(markdown);
            OapiRobotSendResponse response = client.execute(request);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
